{% extends "document_management/base.html" %}

{% block page_link %}
    <link rel="stylesheet" href="../../static/system_setup/css/style.css">
    <link rel="stylesheet" type="text/css" href="../../static/personal_center/css/index.css">
    <link rel="stylesheet" type="text/css" href="../../static/personal_center/css/common.css">
    <script type="text/javascript" src="../../static/personal_center/js/index.js"></script>
{% endblock %}

{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }

        #clsy_table tr:hover {
            background: #cfcfcf;
        }

        #clsy_table tr th {
            text-align: center;
            line-height: 35px;
            border-top: #cfcfcf solid 1px;
            border-right: #cfcfcf solid 1px;
        }

        #clsy_table {
            table-layout: fixed;
            width: 100%;
            border-collapse: separate;
            border-spacing: 0;
            border: 1px solid #DDDDDD;
        }

        #clsy_table tr td {
            line-height: 35px;
            border-top: #cfcfcf solid 1px;
            border-right: #cfcfcf solid 1px;
        }

        #clsy_table thead tr th {
            position: sticky;
            top: 0;
            background: #F4F4F5;
            height: 30px;
        }

        .navigation-bar li {
            display: inline-block;
        }

        .button {
            width: 95px;
            height: 30px;
            border: #ccc solid 0.5px;
            border-radius: 3px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 12px;
            -webkit-transition-duration: 0.4s; /* Safari */
            transition-duration: 0.4s;
            cursor: pointer;
        }

        .button4 {
            background-color: #e8e8e8;
            color: black;
            border: 0.5px solid #ccc;
        }

        .button4:hover {
            background-color: #e8e8e8;
            box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
        }

        .button4:active {
            box-shadow: 0 5px #666;
            transform: translateY(4px);
        }

        .gm-ready {
            height: 80%;
        }
        .add-backbround-color {
            border-left: #1E90FF solid 3px;
            color: #1E90FF;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div style="display: inline-block;vertical-align: top;width: 15%;height: 99%;background: white;margin-top: 5px;margin-left: 10px;">
        <div style="height: 40px;padding-left: 5px;border-bottom: #8c939d solid 1px;line-height: 40px;font-size: 16px;">
            <img src="../../static/personal_center/img/收文管理.png" style="width: 18px;height: 25px;margin-top: -8px;">
            文件分类
        </div>
        {% for k in source_list %}
            <div style="width: 95%;height: 35px;line-height: 35px;cursor: pointer;">
                <div data-value="{{ k.source }}"
                     class="onclick-search {% if forloop.counter == 1 %}add-backbround-color{% endif %}"
                     style="padding-left: 5px;">{{ k.source_describe }} <span
                        style="padding: 4px 0; border-radius: 3px; font-size: 10px; float: right; background: #8c939d; width: 26px; height: 26px; margin-top: 5px; line-height: 20px; text-align: center; display: table-row;color: white;">
                    {{ k.num }}
            </span>
                </div>
            </div>
            <hr>
        {% endfor %}
    </div>

    <div style="display: inline-block;vertical-align: top;width: 83.5%;height: 99%;margin-top: 5px;">
        <div class="headline">
            <section class="search-area">
                <div class="sa-ele" style="width: 20%;">
                    <input class="se-con" name="user" placeholder="输入部门或者发布人"
                           style="width: 100%;height: 30px;border-radius: 3px;">
                </div>
                <div class="sa-ele" style="width: 7%;">
                    <button class="search-action" style="width: 100%;height: 30px;border-radius: 3px;">搜索
                    </button>
                </div>
            </section>
        </div>
        <div id="my_application" style="width: 100%;height: 95.3%;overflow: auto;background-color: white;">
            <div class="right-box" style="width: 100%;height: 100%;margin-top: 0;">
                <div style="height: 100%;width: 100%;overflow: auto;border-bottom: #cccccc solid 1px;background-color: white;">
                    <section class="grid-main">
                        <table id="main_table"></table>
                    </section>
                </div>
            </div>
        </div>
    </div>


{% endblock %}

{% block script %}
    <script>
        window.onload = function () {
            document.getElementById("loading").style.display = "none";
            document.getElementById("doc_management").className = "add_class";
            document.getElementById("sys_doc").className = "add-nav-active";
        };
        var data_value_temp = ''
        function select_all_option(tag) {
            var button_li = document.getElementsByClassName('checkbox_file');
            for (var i = 0; i < button_li.length; i++) {
                button_li[i].checked = "true";
            }
            console.log(button_li)
        }

        const gridManagerName = "test",
            TYPE_MAP = {1: "HTML/CSS", 2: "nodeJS", 3: "javaScript", 4: "前端鸡汤", 5: "PM Coffee", 6: "前端框架", 7: "前端相关"},
            GM_PUBLISH_METHOD_MAP = {
                init: {key: "init", relyInit: !1, title: "初始化", code: 'demo1.initGM(document.querySelector("table"));'},
                get: {key: "get", relyInit: !0, title: "获取表格的实时配置信息", code: `GridManager.get('${gridManagerName}');`},
                version: {key: "version", relyInit: !1, title: "获取当前GridManager的版本号", code: "GridManager.version;"},
                getLocalStorage: {
                    key: "getLocalStorage",
                    relyInit: !0,
                    title: "获取表格用户记忆",
                    code: `GridManager.getLocalStorage('${gridManagerName}');`
                },
                resetLayout: {
                    key: "resetLayout",
                    relyInit: !0,
                    title: "重置表格布局",
                    code: `GridManager.resetLayout('${gridManagerName}', '800px', '500px');`
                },
                clear: {
                    key: "clear",
                    relyInit: !0,
                    title: "清除表格记忆数据",
                    code: `GridManager.clear('${gridManagerName}');`
                },
                getTableData: {
                    key: "getTableData",
                    relyInit: !0,
                    title: "获取指定tr所使用的数据",
                    code: `GridManager.getTableData('${gridManagerName}');`
                },
                getRowData: {
                    key: "getRowData",
                    relyInit: !0,
                    title: "获取指定tr所使用的数据",
                    code: `GridManager.getRowData('${gridManagerName}', document.querySelector("table[grid-manager=${gridManagerName}] tbody tr"));`
                },
                updateRowData: {
                    key: "updateRowData",
                    relyInit: !0,
                    title: "更新指定行所使用的数据",
                    code: `GridManager.updateRowData('${gridManagerName}', 'id', {id: 112, title: 'ccc'});`
                },
                updateTreeState: {
                    key: "updateTreeState",
                    relyInit: !0,
                    title: "更新树的展开状态",
                    code: `GridManager.updateTreeState('${gridManagerName}', true);`
                },
                setSort: {
                    key: "setSort",
                    relyInit: !0,
                    title: "手动设置排序",
                    code: `GridManager.setSort('${gridManagerName}', {createDate: 'ASC'});`
                },
                setConfigVisible: {
                    key: "setConfigVisible",
                    relyInit: !0,
                    title: "设置表头配置区域可视状态",
                    code: `GridManager.setConfigVisible('${gridManagerName}', true);`
                },
                setLineHeight: {
                    key: "setLineHeight",
                    relyInit: !0,
                    title: "配置行的高度",
                    code: `GridManager.setLineHeight('${gridManagerName}', '70px');`
                },
                showTh: {
                    key: "showTh",
                    relyInit: !0,
                    title: "设置列为可视状态",
                    code: `GridManager.showTh('${gridManagerName}', 'pic');`
                },
                hideTh: {
                    key: "hideTh",
                    relyInit: !0,
                    title: "设置列为隐藏状态",
                    code: `GridManager.hideTh('${gridManagerName}', 'pic');`
                },
                exportGrid: {
                    key: "exportGrid",
                    relyInit: !0,
                    title: "导出指定表格",
                    code: `GridManager.exportGrid('${gridManagerName}', 'demo中使用的导出').then(res=>{console.log('success')}).catch(err=>{console.error('error', err)});`
                },
                setQuery: {
                    key: "setQuery",
                    relyInit: !0,
                    title: "更改在生成组件时所配置的参数query",
                    code: `GridManager.setQuery('${gridManagerName}', {'userName':'baukh','sex':'男'});`
                },
                setAjaxData: {
                    key: "setAjaxData",
                    relyInit: !0,
                    title: "用于再次配置ajaxData数据",
                    code: `GridManager.setAjaxData('${gridManagerName}', {data: [{title: '通过setAjaxData动态添加的数据，其它项为空'}], totals: 1});`
                },
                refreshGrid: {
                    key: "refreshGrid",
                    relyInit: !0,
                    title: "刷新表格",
                    code: `GridManager.refreshGrid('${gridManagerName}');`
                },
                renderGrid: {
                    key: "renderGrid",
                    relyInit: !0,
                    title: "渲染表格",
                    code: `GridManager.renderGrid('${gridManagerName}');`
                },
                getCheckedTr: {
                    key: "getCheckedTr",
                    relyInit: !0,
                    title: "获取当前选中的行",
                    code: `GridManager.getCheckedTr('${gridManagerName}');`
                },
                getCheckedData: {
                    key: "getCheckedData",
                    relyInit: !0,
                    title: "获取选中行的渲染数据",
                    code: `GridManager.getCheckedData('${gridManagerName}');`
                },
                setCheckedData: {
                    key: "setCheckedData",
                    relyInit: !0,
                    title: "设置选中的数据",
                    code: `GridManager.setCheckedData('${gridManagerName}', [GridManager.getTableData('${gridManagerName}')[1]]);`
                },
                cleanData: {
                    key: "cleanData",
                    relyInit: !0,
                    title: "清除指定表格数据",
                    code: `GridManager.cleanData('${gridManagerName}');`
                },
                print: {key: "print", relyInit: !0, title: "打印当前页", code: `GridManager.print('${gridManagerName}');`},
                showRow: {
                    key: "showRow",
                    relyInit: !0,
                    title: "显示隐藏行",
                    code: `GridManager.showRow('${gridManagerName}', 1);`
                },
                hideRow: {
                    key: "hideRow",
                    relyInit: !0,
                    title: "隐藏行",
                    code: `GridManager.hideRow('${gridManagerName}', 1);`
                },
                showLoading: {
                    key: "showLoading",
                    relyInit: !0,
                    title: "显示加载中",
                    code: `GridManager.showLoading('${gridManagerName}');`
                },
                hideLoading: {
                    key: "hideLoading",
                    relyInit: !0,
                    title: "隐藏加载中",
                    code: `GridManager.hideLoading('${gridManagerName}', 300);`
                },
                destroy: {
                    key: "destroy",
                    relyInit: !0,
                    title: "消毁指定的GridManager实例",
                    code: `GridManager.destroy('${gridManagerName}');`
                }
            }, arg = {
                gridManagerName: "test",
                width: "100%",
                height: "100%",
                autoOrderConfig: {fixed: "left"},
                checkboxConfig: {key: "id", fixed: "left"},
                supportAjaxPage: !0,
                sortMode: "single",
                supportMenu: !0,
                menuHandler: e => (e.unshift({
                    content: "自定义菜单", line: !0, onClick: e => {
                        alert(e)
                    }
                }), e),
                useCellFocus: !0,
                useHideRow: !0,
                supportMoveRow: !0,
                moveRowConfig: {
                    key: "priority", useSingleMode: !0, fixed: "left", handler: (e, t) => {
                        console.log(e, t)
                    }
                },
                disableCache: !1,
                ajaxData: function (e, t) {
                    var local_host = window.location.host;          // 获取当前IP
                    return "/document-management/document_center_view"
                },
                exportConfig: {
                    fileName: e => {
                        const t = new Date;
                        let a = `${t.getFullYear()}-${t.getMonth() + 1}-${t.getDate()}`;
                        for (let t in e) a = `${a}-${t}=${e[t]}`;
                        return a
                    }, suffix: "xls"
                },
                ajaxType: "POST",
                checkedBefore: function (e, t, a) {
                    return console.log("checkedBefore==", e, t, a), a && 90 === a.id && alert("该节点在checkedBefore中配置为不可选"), a && 90 !== a.id
                },
                checkedAfter: function (e, t, a) {
                    console.log("checkedAfter==", e, t, a)
                },
                checkedAllBefore: function (e, t) {
                    console.log("checkedAllBefore==", e, t)
                },
                checkedAllAfter: function (e, t) {
                    console.log("checkedAllAfter==", e, t)

                },
                sortingBefore: function (e) {
                    console.log("sortingBefore", e)
                },
                sortingAfter: function (e) {
                    console.log("sortingAfter", e)
                },
                ajaxBeforeSend: function (e) {
                    console.log("ajaxBeforeSend")
                },
                ajaxSuccess: function (e) {
                    console.log("ajaxSuccess")
                },
                ajaxError: function (e) {
                    console.log("ajaxError")
                },
                ajaxComplete: function (e) {
                    console.log("ajaxComplete")
                },
                adjustBefore: e => {
                    console.log("adjustBefore=>", e)
                },
                adjustAfter: e => {
                    console.log("adjustAfter=>", e)
                },
                responseHandler: e => (e.data.forEach((e => {
                    e.priority = e.id
                })), e),
                rowRenderHandler: (e, t) => e,
                emptyTemplate: e => `<div style="text-align: center;">${e.query.title ? "搜索为空" : "暂无数据"}</div>`,
                columnData: [
                    {
                        key: "doc_name",
                        text: "文件名称",
                        align: "center",
                        disableMoveRow: !0
                    }, {
                        key: "doc_type",
                        text: "文件类型",
                        align: "center",
                    }, {
                        key: "file_size",
                        text: "文件大小",
                        align: "center",
                    }, {
                        key: "doc_depart",
                        text: "所属部门",
                        align: "center",
                    }, {
                        key: "user",
                        text: "发布人",
                        align: "center",
                    }, {
                        key: "upload_time",
                        text: "上传时间",
                        align: "center",
                    }, {
                        key: "action",
                        width: "100px",
                        align: "center",
                        fixed: "right",
                        disableMoveRow: !0,
                        disableRowCheck: !0,
                        text: '<span style="color: red">操作</span>',
                        template: (e, t) => `<a class="plugin-action" target="_blank" id="${t.id}" href="${t.file_path}" >查看</a>`
                    }]
            }, demo1 = {
                initSearch: function () {
                    document.querySelector(".search-action").addEventListener("click", (function () {
                        change_color(data_value_temp);
                        var e = {
                            search_value: document.querySelector('[name="user"]').value,
                            datavalue:data_value_temp,
                        };
                        table.GM("setQuery", e, (function () {
                            console.log("setQuery执行成功````````````````", e)
                        }))

                    }))
                }, initFN: () => {

                }, initGM: function () {
                    new window.GridManager(table, arg, (e => {
                        console.log("渲染完成后的回调函数:", e), console.log(arg.columnData)
                    }))
                }, editRowData: function (e) {
                    window.GridManager.updateRowData("test", "id", {
                        id: window.parseInt(e.getAttribute("data-id")),
                        lastDate: (new Date).getTime()
                    })
                }
            }, table = document.querySelector("table");
        demo1.initSearch(table), demo1.initGM(table), demo1.initFN();

        var onlick_list = document.getElementsByClassName("onclick-search");

        for (var i = 0; i < onlick_list.length; i++) {
            onlick_list[i].onclick = function () {
                change_color(this.getAttribute("data-value"));
                data_value_temp = this.getAttribute("data-value")
                var e = {
                    datavalue: this.getAttribute("data-value")
                };
                table.GM("setQuery", e, (function () {
                    console.log(e)
                    console.log("setQuery执行成功")
                }))
            }
        }

        function change_color(datavalue) {
            for (var j = 0; j < onlick_list.length; j++) {
                if (onlick_list[j].getAttribute("data-value") === datavalue) {
                    onlick_list[j].className = "onclick-search add-backbround-color";
                } else {
                    onlick_list[j].className = "onclick-search";
                }
            }
        }

        function Judge_authority(ele_id, source) {
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/document-management/check_document_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("source=" + source + "&id=" + ele_id);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate['code'] === 200) {
                            window.open(JsonDate['file_path'])
                        } else {
                            alert('该文件还未公开！')
                        }
                    }
                }
            };
        }
    </script>
{% endblock %}